import { previewImg } from '../../../../utils/util'

Component({
  properties: {
    item: {
      type: Object,
      value: {}
    }
  },
  data: {},
  methods: {
    toggleMore () {
      this.data.item.showMore = !this.data.item.showMore
      this.setData({
        'item.showMore': this.data.item.showMore
      })
    },
    seeDetail () {
      wx.$nav.navigateTo(`/pages/demand/detail/index?id=${this.data.item.id}`)
    },
    previewImage ({ currentTarget: { dataset: { file, urls } } }) {
      let newUrls = urls.map(item => { return item.fileUrl })
      previewImg(file, newUrls)
    },
  },
  ready () {
    let query = this.createSelectorQuery()
    query.select('.demand-item-context').boundingClientRect(rect => {
      if (rect.height > 20 * 3) {
        this.setData({ 'item.showMore': true, 'item.showMoreBtn': true })
      }
    }).exec()
  }
})